#pragma once
#include "..\utils\GameMath.h"
#include <vector>
#include "..\nodes\Node.h"
#include "..\buffer\TransformedVertexBuffer.h"
#include "..\content\ResManager.h"
#include "..\content\BitmapFont.h"
#include "..\renderer\IndexVertexBuffer.h"

namespace ds {

struct TextEntry {
	uint32 id;
	std::string text;
	Vec2 pos;
	Color color;
	float scale;
	bool active;
};

class TextNode : public Node {

typedef std::map<uint32,TextEntry> TextEntries;
typedef std::map<uint32,TextEntry>::iterator TextEntriesIterator;
public:
	TextNode(const std::string& name,const std::string& materialName,const std::string& bitmapFont);
	virtual ~TextNode();
	void prepareRendering();
	void draw();
	void rebuild();
	void init() {}
	void loadContent(ResManager& resourceManager) {
		m_Font = resourceManager.getBitmapFontByName(m_FontName.c_str());
	}
	TextEntry& getText(int index) {
		return m_TextEntries[index];
	}
	void setText(uint32 index,const Vec2& pos,const Color& color,const std::string& text,float scale = 1.0f) {
		TextEntry te;
		te.pos = pos;
		te.id = index;
		te.text = text;
		te.scale = scale;
		te.active = true;
		m_TextEntries[index] = te;
	}
	uint32 addText(const Vec2& pos,const std::string& txt) {
		TextEntry te;
		te.pos = pos;
		te.id = m_TextCounter;
		te.text = txt;
		te.scale = 1.0f;
		te.active = true;
		m_TextEntries[m_TextCounter] = te;
		++m_TextCounter;
		return te.id;
	}
private:		
	std::string m_FontName;
	BitmapFont* m_Font;
	TransformedTexturedBuffer* m_Buffer;
	int m_Total;
	uint32 m_TextCounter;
	TextEntries m_TextEntries;
};

};

